﻿using Avalon.Core.MVC.StateBags;
using Avalon.Core.Data;
using System;

namespace Avalon.Core.MVC.Actions
{
    //public sealed class DeleteEntityAction<TModel> where TModel : class, IEntity, new()
    //{
    //    private readonly IEntityBag<TModel> _bag;

    //    public DeleteEntityAction(IEntityBag<TModel> bag)
    //    {
    //        _bag = bag;
    //    }

    //    public void Execute()
    //    {
    //        try
    //        {
    //            if (_bag.Model == null) throw new Exception("Cannot delete a non existing model");

    //            IRepository<TModel> lRepository = RepositoryConfig.Initialize<TModel>();
    //            lRepository.Delete(_bag.Model.Id);
    //            lRepository.SaveChanges();
    //        }
    //        catch (Exception lEx)
    //        {
    //            _bag.Error = new Exception(string.Format("Failed to delete entity, name: {0}", typeof(TModel).Name), lEx);
    //        }
    //    }

    //    public void Execute(Guid id)
    //    {
    //        try
    //        {
    //            IRepository<TModel> lRepository = RepositoryConfig.Initialize<TModel>();
    //            lRepository.Delete(id);
    //            lRepository.SaveChanges();
    //        }
    //        catch (Exception lEx)
    //        {
    //            _bag.Error = new Exception(string.Format("Failed to delete entity, name: {0}", typeof(TModel).Name), lEx);
    //        }

    //    }
    //}
}